package org.desktop.web.shared.domain.entities;

import java.io.Serializable;

import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the SUB_PROJECTS database table.
 * 
 */
@Entity
@Table(name="SUB_PROJECTS")
@NamedQuery(name="SubProject.findAll", query="SELECT s FROM SubProject s")
@JsonAutoDetect(fieldVisibility=Visibility.ANY)
@JsonIgnoreProperties(value={"timesheets","usersProjects"})
public class SubProject implements Serializable, com.google.gwt.user.client.rpc.IsSerializable {
	private static final long serialVersionUID = 1L;
	private int id;
	private boolean closed;
	private String descSubProject;
	private Date endDate;
	private Date startDate;
	
	@JsonProperty("idProject")
	private Project project;
	private List<Timesheet> timesheets;
	private List<UsersProject> usersProjects;

	public SubProject() {
	}


	@Id
	@Column(unique=true, nullable=false)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}


	public boolean getClosed() {
		return this.closed;
	}

	public void setClosed(boolean closed) {
		this.closed = closed;
	}


	@Column(name="DESC_SUB_PROJECT", length=45)
	public String getDescSubProject() {
		return this.descSubProject;
	}

	public void setDescSubProject(String descSubProject) {
		this.descSubProject = descSubProject;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="END_DATE")
	public Date getEndDate() {
		return this.endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}


	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="START_DATE")
	public Date getStartDate() {
		return this.startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}


	//bi-directional many-to-one association to Project
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ID_PROJECT", nullable=false)
	public Project getProject() {
		return this.project;
	}

	public void setProject(Project project) {
		this.project = project;
	}


	//bi-directional many-to-one association to Timesheet
	@OneToMany(mappedBy="subProject")
	public List<Timesheet> getTimesheets() {
		return this.timesheets;
	}

	public void setTimesheets(List<Timesheet> timesheets) {
		this.timesheets = timesheets;
	}

	public Timesheet addTimesheet(Timesheet timesheet) {
		getTimesheets().add(timesheet);
		timesheet.setSubProject(this);

		return timesheet;
	}

	public Timesheet removeTimesheet(Timesheet timesheet) {
		getTimesheets().remove(timesheet);
		timesheet.setSubProject(null);

		return timesheet;
	}


	//bi-directional many-to-one association to UsersProject
	@OneToMany(mappedBy="subProject")
	public List<UsersProject> getUsersProjects() {
		return this.usersProjects;
	}

	public void setUsersProjects(List<UsersProject> usersProjects) {
		this.usersProjects = usersProjects;
	}

	public UsersProject addUsersProject(UsersProject usersProject) {
		getUsersProjects().add(usersProject);
		usersProject.setSubProject(this);

		return usersProject;
	}

	public UsersProject removeUsersProject(UsersProject usersProject) {
		getUsersProjects().remove(usersProject);
		usersProject.setSubProject(null);

		return usersProject;
	}

}